# 字典的创建
# 键不能重复
d = {
    "name": "huang",
    "age": 18,
    # "name": "hao"  # 键重复的话，会覆盖前面的值
}
print(d, type(d))
d = {}
print(d, type(d))
d = dict()
print(d, type(d))

# 新增键值对
d["height"] = 180
print(d)
# 获取键值对
print(d["age"])
print(d.get("age"))
# 修改键值对
d["age"] = 20
print(d)

print("name" in d)  # 判断键在不在字典中

print("=" * 50)
# 字典的遍历
# {'height': 180}
for i in d:
    print(i, d[i])

print(d.items())
print(d.keys())
print(d.values())
for k, v in d.items():
    print(k, v)
for k in d.keys():
    print(k, end=" ")
print()
for v in d.values():
    print(v, end=" ")
print()
d.pop("name")
print(d)
d2 = d.copy()
print("d的拷贝:", d2)
d.popitem()
print("pop:", d)
d.update({"hobby":"football"})
print(d)

d.clear()
print(d)